//************************************************
//  *Author：jxx
//  *QQ：283591387
//  *自定义业务逻辑扩展
//************************************************
import { mapMutations } from 'vuex';
import extend from './q_aftersaleExtend.js';
import options from './q_aftersaleOptions.js';
export default function () {
	return {
		data() {
			let _options = options();
			_options.extend = extend;
			return {
				options: _options
			};
		},
		methods: {
			...mapMutations(['setSalesContractDataStore']),
			onInited() {
				//设置自定义格式显示
				this.columns.forEach((column) => {
					if (column.field == 'Servicing_time') {
						column.formatter = true;
					}
				});
			},
			formatter(row, column, index) {
				console.log(132456, column.field);
				//自定义格式化
				if (column.field == 'Servicing_time') {
					return row[column.field] ? row[column.field] + ' 天' : '';
				}
				return '';
			},
			rowClick(index, row, column) {
				return false;
			},
			cellClick(index, row, column) {
				//单元格击事件(默认触发编辑)
				//仅onInited中设置：this.direction = "horizontal", this.columns的字段设置为click=true后生效
				return true;
			},
			rowButtons(index, row) {
				let buttonList = [];
				let pages = getCurrentPages();
				// console.log('pages', pages);
				let prevPage = pages[pages.length - 2];
				if (
					pages.length >= 3 &&
					(prevPage.route == 'aftersaleinfo/q_aftersale_notarize/q_aftersale_notarize' || prevPage.route == 'pages/addPage/addPage') &&
					row.AuditStatus === 1
				) {
					buttonList.push({
						text: '选择售后单',
						type: 'success ',
						shape: 'circle'
					});
				}
				if (row.AuditStatus === 0) {
					buttonList.push({
						text: '审核',
						type: 'error',
						shape: 'circle'
					});
					if (buttonList.length != 2) {
						buttonList.push({
							text: '编辑',
							type: 'warning',
							shape: 'circle'
						});
					}
				} else {
					buttonList.push({
						text: '查看审核',
						type: 'primary',
						shape: 'circle'
					});
				}
				//返回查看审批按钮
				return buttonList;
			},
			rowButtonClick(btn, index, row) {
				//列表显示的按钮点击事件
				if (btn.text == '编辑') {
					//这里key 要和 url上的biaoming一致
					uni.setStorageSync('q_aftersale', row);
					const optionsObj = {
						editFormOptions: this.options.editFormOptions,
						detailtable: this.options.table
					};
					uni.setStorageSync('optionsObj', JSON.stringify(optionsObj));
					uni.navigateTo({
						url: '/pages/addPage/addPage?biaoming=q_aftersale&currentAction=Update&ID=Aftersale&detailTableShow=false'
					});
					return;
				}
				if (btn.text == '选择售后单') {
					// 清空明细表
					this.$store.commit('clearOperations_recycleList');
					const obj = JSON.stringify({
						Voucher_sub_aftersale: row.Voucher_sub,
						Aftersale_ID: row.Aftersale,
						Client: row.Client
					});
					uni.setStorageSync('obj', obj);
					uni.navigateBack();
					return;
				}
				try {
					this.setSalesContractDataStore({ workTable: 'q_aftersale', tableKey: row.Aftersale });
					uni.navigateTo({
						url: `/pages/aftersaleinfo/q_aftersale/q_aftersaleAduit?workTable=q_aftersale&&tableKey=` + row.Aftersale
					});
				} catch (e) {
					//TODO handle the exception
					console.log(e);
				}
			},
			searchBefore(params) {
				//查询前
				return true;
			},
			updateBefore(formData) {
				//更新保存前操作
				return true;
			},
			addBefore(formData) {
				//新建保存前操作
				formData.mainData.Contract_state = '0';
				formData.mainData.Maintain_state = '0';
				return true;
			},
			searchFormOnChange(field, value) {
				//查询弹出框下拉框或日期选中事件
				//if(field=="字段"){
				// 	console.log(value)
				//}
			},
			editFormOnChange(field, value) {
				//新建编辑弹出框下拉框或日期选中事件
				//if(field=="字段"){
				// 	console.log(value)
				//}
			}
		}
	};
}
